### --- Test setup ---

if(FALSE) {
	## Not really needed, but can be handy when writing tests
	library("RUnit")
	library("unsupervisedMicroarray")
	
}


library(plsgenomics)
data(leukemia)
library(rda)
data(brain)
brainS <-list(X=brain.x,Y=brain.y)

### --- Test functions ---
#check if virtual classes are virtual 
test.bootstrapSetFormat <- function()
{
	
	nboots <-3
	rboots <- new("RowBootstrapedSet",leukemia,nboots)
	
	leukXdim <-dim(leukemia$X)
	leukYlen <-length(leukemia$Y)
	
	checkTrue(getSamplesNumber(rboots) == nboots)
	
	for(i in 1:nboots){
		tmpSet <- getAt(rboots,i)
		
		checkIdentical(dim(tmpSet$X),leukXdim)
		checkIdentical(length(tmpSet$Y),leukYlen)
		
	}
	
	checkException(getAt(rboots,(nboots+1)))
	checkException(new("RowBootstrapedSet",list(),nboots))
	checkException(new("RowBootstrapedSet",leukemia,-1))
	checkException(new("RowBootstrapedSet",list(),-1))
	
	#check changeSet
	
	leukXdim <-dim(brainS$X)
	leukYlen <-length(brainS$Y)
	
	print("SET change")
	print("BRAINS");
	print(brainS$Y)
	rboots <- changeSet(rboots,inputSet=brainS)
	
	
	checkTrue(getSamplesNumber(rboots) == nboots)
	
	for(i in 1:nboots){
		tmpSet <- getAt(rboots,i)
		
		checkIdentical(dim(tmpSet$X),leukXdim)
		checkIdentical(length(tmpSet$Y),leukYlen)
		
	}
	
	checkException(getAt(rboots,(nboots+1)))
	checkException(new("RowBootstrapedSet",list(),nboots))
	checkException(new("RowBootstrapedSet",leukemia,-1))
	checkException(new("RowBootstrapedSet",list(),-1))
	
	
	
}

test.bootstrapSetFormat_NormNoise <- function()
{
	nboots <-3
	rboots <- new("NormNoiseRowBootstrapedSet",leukemia,nboots)
	
	leukXdim <-dim(leukemia$X)
	leukYlen <-length(leukemia$Y)
	
	checkTrue(getSamplesNumber(rboots) == nboots)
	
	for(i in 1:nboots){
		tmpSet <- getAt(rboots,i)
		
		checkIdentical(dim(tmpSet$X),leukXdim)
		checkIdentical(length(tmpSet$Y),leukYlen)
		
	}
	
	checkException(getAt(rboots,(nboots+1)))
	checkException(new("NormNoiseRowBootstrapedSet",list(),nboots))
	checkException(new("NormNoiseRowBootstrapedSet",leukemia,-1))
	checkException(new("NormNoiseRowBootstrapedSet",list(),-1))
	
	#check changeSet
	
	leukXdim <-dim(brainS$X)
	leukYlen <-length(brainS$Y)
	
	print("SET change")
	print("BRAINS");
	print(brainS$Y)
	rboots <- changeSet(rboots,inputSet=brainS)
	
	
	checkTrue(getSamplesNumber(rboots) == nboots)
	
	for(i in 1:nboots){
		tmpSet <- getAt(rboots,i)
		
		checkIdentical(dim(tmpSet$X),leukXdim)
		checkIdentical(length(tmpSet$Y),leukYlen)
		
	}
	
	checkException(getAt(rboots,(nboots+1)))
	checkException(new("RowBootstrapedSet",list(),nboots))
	checkException(new("RowBootstrapedSet",leukemia,-1))
	checkException(new("RowBootstrapedSet",list(),-1))
	
	
}

test.bootstrapSetFormat_UnifNoise <- function()
{
	#leukemia$X <-leukemia$X[,1:100]
	nboots <-3
	Ymax <- max(leukemia$Y)
	rboots <- new("UnifNoiseRowBootstrapedSet",leukemia,nboots)
	
	leukXdim <-dim(leukemia$X)
	leukYlen <-length(leukemia$Y)
	
	checkTrue(getSamplesNumber(rboots) == nboots)
	
	for(i in 1:nboots){
		tmpSet <- getAt(rboots,i)
		
		checkIdentical(dim(tmpSet$X)[2],leukXdim[2])
		checkTrue(dim(tmpSet$X)[1]>=leukXdim[1])
		checkTrue(length(tmpSet$Y)>=leukYlen)
		checkTrue(max(tmpSet$Y) == Ymax+1)
		
	}
	
	checkException(getAt(rboots,(nboots+1)))
	checkException(new("UnifNoiseRowBootstrapedSet",list(),nboots))
	checkException(new("UnifNoiseRowBootstrapedSet",leukemia,-1))
	checkException(new("UnifNoiseRowBootstrapedSet",list(),-1))
	
	#check changeSet
	
	leukXdim <-dim(brainS$X)
	leukYlen <-length(brainS$Y)
	Ymax <- max(brainS$Y)
	
	print("SET change")
	print("BRAINS");
	print(brainS$Y)
	rboots <- changeSet(rboots,inputSet=brainS)
	
	
	checkTrue(getSamplesNumber(rboots) == nboots)
	
	for(i in 1:nboots){
		tmpSet <- getAt(rboots,i)
		
		checkIdentical(dim(tmpSet$X)[2],leukXdim[2])
		checkTrue(dim(tmpSet$X)[1]>=leukXdim[1])
		checkTrue(length(tmpSet$Y)>=leukYlen)
		checkTrue(max(tmpSet$Y) == Ymax+1)
		
	}
	
	checkException(getAt(rboots,(nboots+1)))
	checkException(new("RowBootstrapedSet",list(),nboots))
	checkException(new("RowBootstrapedSet",leukemia,-1))
	checkException(new("RowBootstrapedSet",list(),-1))
	
	
}